package com.coffee.takeoutserver.service.impl;

import com.coffee.takeoutserver.bean.MyCollection;
import com.coffee.takeoutserver.bean.MyCollectionExample;
import com.coffee.takeoutserver.bean.Seller;
import com.coffee.takeoutserver.dao.MyCollectionMapper;
import com.coffee.takeoutserver.dao.SellerMapper;
import com.coffee.takeoutserver.service.CollectionService;
import com.coffee.takeoutserver.service.HomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
class CollectionServiceImpl implements CollectionService {
    @Autowired
    private MyCollectionMapper collectionMapper;

    @Override
    public MyCollection getCollectionByUserId(int userId) {
        MyCollectionExample collectionExample = new MyCollectionExample();
        collectionExample.setOrderByClause("id desc");
        MyCollectionExample.Criteria criteria = collectionExample.createCriteria();
        criteria.andUseridEqualTo(userId);
        List<MyCollection> collections= collectionMapper.selectByExample(collectionExample);
        return collections==null||collections.size()==0?null:collections.get(0);
    }

    @Override
    public void updateCollectionByUserId(MyCollection collection) {
        MyCollectionExample collectionExample = new MyCollectionExample();
        MyCollectionExample.Criteria criteria = collectionExample.createCriteria();
        criteria.andUseridEqualTo(collection.getUserid());
        collectionMapper.updateByExampleSelective(collection,collectionExample);
    }

    @Override
    public void addCollection(MyCollection collection) {
        collectionMapper.insertSelective(collection);
    }
}
